package api

import (
	"RESTfulAPI/basic/config"
	__ "RESTfulAPI/basic/proto"
	"RESTfulAPI/handler/request"
	"RESTfulAPI/utils"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func UploadActivity(c *gin.Context) {
	file, _ := c.FormFile("file")
	if file.Size > 1024*1024*2 {
		c.JSON(http.StatusOK, gin.H{
			"code": 200,
			"msg":  "文件太大",
			"data": error.Error,
		})
		return
	}
	// 保存文件到本地
	filename := "D:\\gowork\\src\\zg4\\2212a\\ks\\shopping_goods\\uploads\\" + file.Filename
	if err := c.SaveUploadedFile(file, filename); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 200,
			"msg":  "文件保存失败",
			"data": error.Error,
		})
		return
	}
	utils.UploadOss(filename, file.Filename)
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "文件上传成功",
		"data": filename,
	})

}

func ListActivity(c *gin.Context) {
	var req request.ListActivityReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 200,
			"msg":  "参数错误",
			"data": error.Error,
		})
		return
	}
	r, err := config.UserClient.ListActivity(c, &__.ListActivityReq{
		Id: req.Id,
	})
	if err != nil {
		log.Fatalf("ListActivity failed, err: %v", err)
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": r.Code,
		"msg":  r.Msg,
		"data": r,
	})
}
